`ifndef COVERAGE_PKG_SV
`define COVERAGE_PKG_SV

// coverage model for switch
class coverage_switch extends uvm_component;
    local virtual interface mii_if in_vif;
	local virtual interface mii_if out_vif;


    `uvm_component_utils(coverage_switch)

    covergroup cg_out_data;
        source_mac_addr: coverpoint out_vif.mon_clk.mii_rx_data {
        }
		dv: coverpoint out_vif.mon_clk.mii_rx_dv {}
    endgroup

 	covergroup cg_drive_data;
		destiny_mac_addr: coverpoint in_vif.mon_clk.mii_tx_data {
		}
		en: coverpoint in_vif.mon_clk.mii_tx_en {}
	endgroup

    function new (string name = "switch_coverage", uvm_component parent);
        super.new(name, parent);
        this.cg_out_data = new();
		this.cg_drive_data = new();
    endfunction

    task main_phase(uvm_phase phase);
      fork 
	  	this.do_out_data_sample();
        this.do_drive_data_sample();
      join
    endtask

    task do_out_data_sample();
      forever begin
        @(posedge out_vif.clk);
        this.cg_out_data.sample();
      end
    endtask

	task do_drive_data_sample();
      forever begin
        @(posedge in_vif.clk);
        this.cg_drive_data.sample();
      end
    endtask


    function void report_phase(uvm_phase phase);
      string s;
      super.report_phase(phase);
      s = "\n---------------------------------------------------------------\n";
      s = {s, "COVERAGE SUMMARY \n"}; 
      s = {s, $sformatf("total coverage: %.1f \n", $get_coverage())}; 
      s = {s, $sformatf("  cg_out_data coverage: %.1f \n", this.cg_out_data.get_coverage())}; 
	  s = {s, $sformatf("  cg_drive_data coverage: %.1f \n", this.cg_drive_data.get_coverage())}; 
      s = {s, "---------------------------------------------------------------\n"};
      `uvm_info(get_type_name(), s, UVM_LOW)
    endfunction

    virtual function void build_phase(uvm_phase phase);
        super.build_phase(phase);
        if(!uvm_config_db#(virtual mii_if #(PORT_NUM))::get(this, "", "in_vif", in_vif))
            `uvm_fatal(get_type_name(), "virtual interface must be set for !!!");
		if(!uvm_config_db#(virtual mii_if #(PORT_NUM))::get(this, "", "out_vif", out_vif))
            `uvm_fatal(get_type_name(), "virtual interface must be set for !!!");

    endfunction
endclass: coverage_switch

`endif

